from selenium import webdriver  # 在selenium中引用
from selenium.webdriver.common.by import By
from time import sleep
from options import options


# from test_cases_webtours import service
# url = r'http://172.16.22.105:8080/bsams/front/login.do'
# driver = webdriver.Chrome(options=options)
# driver.get(url)
# driver.maximize_window()  # 扩大页面


class ASMS():
    def __init__(self, driver):
        self.driver = driver

    # 登录
    def login(self, id, name, pwd, vericode):
        self.driver.find_element(By.ID, 'taskId').click()
        self.driver.find_element(By.ID, 'taskId').send_keys(id)
        self.driver.find_element(By.ID, 'loginName').click()
        self.driver.find_element(By.ID, 'loginName').send_keys(name)
        self.driver.find_element(By.ID, 'password').click()
        self.driver.find_element(By.ID, 'password').send_keys(pwd)
        self.driver.find_element(By.ID, 'vericode').click()
        self.driver.find_element(By.ID, 'vericode').send_keys(vericode)
        sleep(1)
        self.driver.find_element(By.CLASS_NAME, 'dl-button.left').click()
        sleep(1)

    # 修改电话
    def phone(self, number):
        self.driver.find_element(By.ID, 'phone').clear()
        self.driver.find_element(By.ID, 'phone').click()
        self.driver.find_element(By.ID, 'phone').send_keys(number)
        self.driver.find_element(By.CLASS_NAME, 'button_fujian').click()
        sleep(3)
        #  弹窗解决办法
        driver.switch_to.alert.accept()
        sleep(3)

    # 修改密码
    def password(self, oldPassword, newPassword1, newPassword2):
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[1]/a').click()  # 选择修改密码
        self.driver.find_element(By.ID, 'oldPassword').click()
        self.driver.find_element(By.ID, 'oldPassword').send_keys(oldPassword)
        self.driver.find_element(By.ID, 'newPassword1').click()
        self.driver.find_element(By.ID, 'newPassword1').send_keys(newPassword1)
        self.driver.find_element(By.ID, 'newPassword2').click()
        self.driver.find_element(By.ID, 'newPassword2').send_keys(newPassword2)
        sleep(1)
        self.driver.find_element(By.CLASS_NAME, 'button_fujian.margin').click()
        sleep(3)
        # 弹窗解决
        driver.switch_to.alert.accept()
        sleep(2)

    # 退出
    def logout(self):
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/a[2]/img').click()
        sleep(3)

    # 资产管理-查询
    def query(self, title):
        self.driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_manage"]/div[1]/a/img').click()
        self.driver.find_element(By.XPATH, '//*[@id="status"]/option[1]').click()
        self.driver.find_element(By.ID, 'title').clear()
        self.driver.find_element(By.ID, 'title').send_keys(title)
        sleep(1)
        self.driver.find_element(By.CLASS_NAME, 'search_button').click()
        sleep(3)

    # 资产管理 新增
    def added(self, content):
        self.driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_manage"]/div[1]/a/img').click()
        self.driver.find_element(By.CLASS_NAME, 'button_true').click()
        self.driver.find_element(By.CLASS_NAME, 'input').clear()
        self.driver.find_element(By.CLASS_NAME, 'input').click()
        self.driver.find_element(By.CLASS_NAME, 'input').send_keys(content)
        self.driver.find_element(By.XPATH, '//*[@id="providerId"]/option[2]').click()
        self.driver.find_element(By.XPATH, '//*[@id="storageId"]/option[2]').click()
        self.driver.find_element(By.CLASS_NAME, 'button_fujian.margin').click()
        sleep(2)
        # 弹窗解决
        driver.switch_to.alert.accept()
        sleep(2)

    # 修改
    def modify(self, names):
        self.driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_manage"]/div[1]/a/img').click()
        self.driver.find_element(By.XPATH,
                                 '/html/body/div[2]/div/div[2]/div[2]/div[3]/table/tbody/tr[2]/td[8]/a[1]').click()
        self.driver.find_element(By.NAME, 'title').clear()
        self.driver.find_element(By.NAME, 'title').click()
        self.driver.find_element(By.NAME, 'title').send_keys(names)
        self.driver.find_element(By.ID, 'storageId').click()
        self.driver.find_element(By.ID, 'providerId').click()
        self.driver.find_element(By.CLASS_NAME, 'button_fujian.margin').click()
        sleep(1)

        # 窗口解决
        driver.switch_to.alert.accept()
        sleep(2)

    # 借用
    def borrow(self, remark):
        self.driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_manage"]/div[1]/a/img').click()
        self.driver.find_element(By.CLASS_NAME, 'padding5').click()
        sleep(1)
        self.driver.find_element(By.XPATH, '//*[@id="departId"]/option[4]').click()
        sleep(1)
        self.driver.find_element(By.ID, 'remark').clear()
        self.driver.find_element(By.ID, 'remark').click()
        self.driver.find_element(By.ID, 'remark').send_keys(remark)
        self.driver.find_element(By.CLASS_NAME, 'button_fujian.margin').click()
        sleep(1)

        # 弹窗确定
        driver.switch_to.alert.accept()

    # 存放地点 查询
    def location(self, title):
        driver.find_element(By.XPATH, '//*[@id="leftmenu_asset_storage"]/div[1]/a/img').click()
        driver.find_element(By.XPATH, '//*[@id="status"]/option[1]').click()
        driver.find_element(By.ID, 'title').clear()
        driver.find_element(By.ID, 'title').click()
        driver.find_element(By.ID, 'title').send_keys(title)
        sleep(1)
        driver.find_element(By.CLASS_NAME, 'search_button').click()
        sleep(1)

    # 供应商
    def supplier(self, test):
        self.driver.find_element(By.XPATH,'//*[@id="leftmenu_asset_provider"]/div[1]/a/img').click()
        self.driver.find_element(By.XPATH, '//*[@id="fmsearch"]/div[1]/select/option[2]').click()
        self.driver.find_element(By.ID, 'title').click()
        self.driver.find_element(By.ID, 'title').send_keys(test)
        self.driver.find_element(By.CLASS_NAME,'search_button').click()
        sleep(3)


if __name__ == '__main__':
    id = 1
    name = 'zhaojunwei01'
    pwd = 123456
    vericode = 'shtd'
    number = 18736117546
    oldPassword = 123456
    newPassword1 = 123456
    newPassword2 = 123456
    query = 11121
    content = '赵zz'
    names = '赵老板'
    remark = '借用一下玩玩'
    title = 'eee'
    test = 'fff'
    url = r'http://172.16.22.105:8080/bsams/front/login.do'
    driver = webdriver.Chrome(options=options)
    driver.get(url)
    asms = ASMS(driver)
    # 登录
    asms.login(id, name, pwd, vericode)
    # 修改手机号
    # asms.phone(number)
    # print('修改完成')
    # 修改密码
    # asms.password(oldPassword, newPassword1, newPassword2)
    # print('修改完成')
    # 资产管理 查询
    # asms.query(query)
    # 资产管理 新增
    # asms.added(content)
    # 修改
    # asms.modify(names)
    # 借用
    # asms.borrow(remark)
    # 存放地点 查询
    # asms.location(title)
    # 存放地点 查新
    # asms.supplier(test)

    driver.quit()
